package cfca.paperless.client.servlet._3_assist._3_02_TransformImageToPdf;

import java.io.File;

import org.apache.commons.io.FileUtils;

import cfca.paperless.client.servlet.PaperlessClient;
import cfca.paperless.client.servlet.PaperlessConfig;
import cfca.paperless.client.util.Base64;
import cfca.paperless.client.util.GUID;
import cfca.paperless.client.util.IoUtil;
import cfca.paperless.client.util.PaperlessUtil;

public class TransformImageToPdfTest01 {

    public static void main(String[] args) throws Exception {
        try {
            PaperlessClient clientBean = new PaperlessClient(PaperlessConfig.assistUrl, 10000, 60000);

            //byte[] pdfFile = IoUtil.read(new FileInputStream("./TestData/businessPdf.pdf"));

            byte[] handwritingData = FileUtils.readFileToByteArray(new File("./TestData/handwriting.png"));
            byte[] identificationBackData = FileUtils.readFileToByteArray(new File("./TestData/1.png"));
            

            String imageBase64List = "<List><Image>" + Base64.toBase64String(handwritingData) + "</Image><Image>" + Base64.toBase64String(identificationBackData) + "</Image></List>";
            String savedPdfId = GUID.generateId();
            System.out.println(imageBase64List);
            byte[] sealedPdf = clientBean.transformImageToPdf(imageBase64List, savedPdfId, PaperlessConfig.operatorCode, PaperlessConfig.channelCode);
      
            String errorRsString = PaperlessUtil.isError(sealedPdf);
            
            if ("".equals(errorRsString)) {
                IoUtil.write("./TestData/output/transformImageToPdf.pdf", sealedPdf);
            } else {
                System.out.println(new String(sealedPdf, "UTF-8"));
            }
            System.out.println(sealedPdf.length);


        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }

   
}
